package com.ywd.platform.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ywd.platform.exception.R;
import com.ywd.platform.service.OssFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author lk
 * @date 2024/6/3 9:50
 */
@RestController
@RequestMapping("/test")
@Tag(name = "文件管理")
public class FileController {

  @Autowired
  private OssFileService ossFileService;

  @GetMapping("/getOssFileToken")
  @Operation(summary = "获取OSS上传文件的-上传令牌")
  @ApiOperationSupport(order = 2)
  public R getOssFileToken() {
    return ossFileService.getOssFileToken();
  }

  @PostMapping("/ossUploadFile")
  @Operation(summary = "上传文件(oss服务器上传)")
  @ApiOperationSupport(order = 3)
  public R ossUploadFile(@Schema(description = "文件") @RequestPart("file") MultipartFile file) {
    return R.ok(ossFileService.ossUploadFile(file));
  }

  @PostMapping("/ossUploadFileList")
  @Operation(summary = "批量上传文件(oss服务器上传)")
  @ApiOperationSupport(order = 4)
  public R ossUploadFileList(@Schema(description = "文件") @RequestPart("files") MultipartFile[] file) {
    return R.ok(ossFileService.ossUploadFileList(file));
  }

}
